package com.lhq.business.repo;

import com.lhq.business.entity.BookShelf;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.mongodb.repository.MongoRepository;

import java.util.List;
import java.util.Optional;

public interface BookShelfRepository extends MongoRepository<BookShelf, String> {
    /**
     * 查询个人书架
     * @param bookShelf
     * @return: java.util.List<com.lhq.business.entity.NovelBook>
     * @author lhq
     * @date: 2024/7/26 10:11
     */
    public default List<BookShelf> findAll(BookShelf bookShelf){
        ExampleMatcher matcher = ExampleMatcher.matching()
                .withStringMatcher(ExampleMatcher.StringMatcher.DEFAULT)
                .withIgnoreNullValues()
                .withIgnorePaths("_class");
        Example<BookShelf> example = Example.of(bookShelf, matcher);
        return this.findAll(example);
    }

    public default Optional<BookShelf> findAllByUserId(String userId){
        BookShelf bookShelf = new BookShelf();
        bookShelf.setUid(userId);
        ExampleMatcher matcher = ExampleMatcher.matching()
                .withStringMatcher(ExampleMatcher.StringMatcher.DEFAULT)
                .withIgnoreNullValues()
                .withIgnorePaths("_class");
        Example<BookShelf> example = Example.of(bookShelf, matcher);
        return this.findOne(example);
    };
}